package com.firefly.service.query.ums;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.firefly.dao.dao.ums.mapper.LogMapper;
import com.firefly.dao.dao.ums.po.LogPo;
import com.firefly.dao.dao.ums.service.LogService;
import com.firefly.dao.dto.ums.LogDto;
import com.firefly.dao.vo.ums.LogListVo;
import com.firefly.dao.vo.ums.LogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;

@Service
public class LogQuery {
    private final LogService logService;
    private final LogMapper logMapper;
    @Autowired
    public LogQuery(LogService logService,LogMapper logMapper){
        this.logService = logService;
        this.logMapper = logMapper;
    }
    public LogListVo getList(LogDto request){
        QueryWrapper<LogPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!request.adminId.isEmpty(),"admin_id", request.adminId);
        Long count = logService.count(queryWrapper);
        queryWrapper.last("limit " + request.offset + "," + request.pageSize);
        List<LogVo> all = logMapper.getList(request);
        LogListVo result = new LogListVo();
        result.setList(all);
        result.setCount(count);
        return result;
    }
}
